package com.tydic.apigateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.filter.factory.StripPrefixGatewayFilterFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient
public class ApiGatewayApplication {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        StripPrefixGatewayFilterFactory.Config config = new StripPrefixGatewayFilterFactory.Config();
        config.setParts(1);
        return builder.routes()
//                .route("path_route", r -> r.path("/a/**").filters(f -> f.stripPrefix(1)).uri("http://localhost:8085"))
//                .route("path_route", r -> r.path("/b/**").filters(f -> f.stripPrefix(1)).uri("http://localhost:8084"))
                .route("path_route", r -> r.path("/a/**").filters(f -> f.stripPrefix(1)).uri("lb://feignconsumer"))
                .route("path_route", r -> r.path("/b/**").filters(f -> f.stripPrefix(1)).uri("lb://ribbonconsumer"))
                .build();
    }
//        @Bean
//        public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//            return builder.routes()
//                    //basic proxy
//                    .route(r -> r.path("/a")
//                            .uri("http://www.baidu.com/")
//                    ).build();
//        }


    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

}
